<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="年月" prop="monthDate">
        <el-date-picker clearable
          v-model="queryParams.monthDate"
          type="month"
          value-format="yyyy-MM"
          placeholder="请选择年月">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dispatch:drivingMonthPlan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dispatch:drivingMonthPlan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dispatch:drivingMonthPlan:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dispatch:drivingMonthPlan:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="drivingMonthPlanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="年月" align="center" prop="monthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.monthDate, '{y}-{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="队别" align="center" prop="dw" />
      <el-table-column label="施工地点" align="center" prop="sgddName" />
      <el-table-column label="支护形式" align="center" prop="zhxs" />
      <el-table-column label="掘进方式" align="center" prop="jjfs" />
<!--      <el-table-column label="掘进断面" align="center" prop="jjdm" />
      <el-table-column label="断面形式" align="center" prop="dmxs" />-->
      <el-table-column label="岩性" align="center" prop="yx" />
      <el-table-column label="运输环节" align="center" prop="yshj" />
      <el-table-column label="天数" align="center" prop="ts" />
      <el-table-column label="日进" align="center" prop="rj" />
      <el-table-column label="月计划" align="center" prop="yjh" />
      <el-table-column label="施工日期" align="center" prop="sgrq" />
      <el-table-column label="人数" align="center" prop="rs" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dispatch:drivingMonthPlan:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dispatch:drivingMonthPlan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改掘进月计划对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="年月" prop="monthDate">
          <el-date-picker clearable
            v-model="form.monthDate"
            type="month"
            value-format="yyyy-MM"
            placeholder="请选择年月">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="队别" prop="db">
          <el-select v-model="form.db" placeholder="请选择队别" clearable>
            <el-option v-for="item in teamOptions" :key="item.drivingTeamId" :label="item.teamName" :value="item.drivingTeamId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="施工地点" prop="sgdd">
          <el-select v-model="form.sgdd" placeholder="请选择施工地点" clearable>
            <el-option v-for="item in tunnelOptions" :key="item.tunnelId" :label="item.tunnelName" :value="item.tunnelId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支护形式" prop="zhxs">
          <el-input v-model="form.zhxs" placeholder="请输入支护形式" />
        </el-form-item>
        <el-form-item label="掘进方式" prop="jjfs">
          <el-input v-model="form.jjfs" placeholder="请输入掘进方式" />
        </el-form-item>
        <el-form-item label="掘进断面" prop="jjdm">
          <el-input v-model="form.jjdm" placeholder="请输入掘进断面" />
        </el-form-item>
        <el-form-item label="断面形式" prop="dmxs">
          <el-input v-model="form.dmxs" placeholder="请输入断面形式" />
        </el-form-item>
        <el-form-item label="岩性" prop="yx">
          <el-input v-model="form.yx" placeholder="请输入岩性" />
        </el-form-item>
        <el-form-item label="运输环节" prop="yshj">
          <el-input v-model="form.yshj" placeholder="请输入运输环节" />
        </el-form-item>
        <el-form-item label="天数" prop="ts">
          <el-input v-model="form.ts" placeholder="请输入天数" />
        </el-form-item>
        <el-form-item label="日进（m）" prop="rj">
          <el-input v-model="form.rj" placeholder="请输入日进" />
        </el-form-item>
        <el-form-item label="月计划（m）" prop="yjh">
          <el-input v-model="form.yjh" placeholder="请输入月计划" />
        </el-form-item>
        <el-form-item label="施工日期" prop="sgrq">
          <el-date-picker clearable
                          v-model="form.sgrq"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择施工日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="人数" prop="rs">
          <el-input v-model="form.rs" placeholder="请输入人数" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDrivingMonthPlan, getDrivingMonthPlan, delDrivingMonthPlan, addDrivingMonthPlan, updateDrivingMonthPlan } from "@/api/dispatch/drivingMonthPlan";
import { listTunnelInfo } from "@/api/dispatch/tunnelInfo";
import { listDrivingTeam } from "@/api/dispatch/drivingTeam";
export default {
  name: "DrivingMonthPlan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //巷道选项
      tunnelOptions:[],
      //队组选项
      teamOptions:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 掘进月计划表格数据
      drivingMonthPlanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        monthDate: null,
        db: null,
        sgdd: null,
        zhxs: null,
        jjfs: null,
        jjdm: null,
        dmxs: null,
        yx: null,
        yshj: null,
        ts: null,
        rj: null,
        yjh: null,
        sgrq: null,
        rs: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    //获取巷道选项
    let query = {pageNum:1,pageSize: 1000}
    listTunnelInfo(query).then(response => {
      this.tunnelOptions = response.rows;
    });

    //获取开掘队选项
    listDrivingTeam(query).then(response => {
      this.teamOptions = response.rows;
    });
  },
  methods: {
    /** 查询掘进月计划列表 */
    getList() {
      this.loading = true;
      listDrivingMonthPlan(this.queryParams).then(response => {
        this.drivingMonthPlanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        drivingMonthPlanId: null,
        mineId: null,
        monthDate: null,
        dw: null,
        db: null,
        sgdd: null,
        zhxs: null,
        jjfs: null,
        jjdm: null,
        dmxs: null,
        yx: null,
        yshj: null,
        ts: null,
        rj: null,
        yjh: null,
        sgrq: null,
        rs: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        sort: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.drivingMonthPlanId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加掘进月计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const drivingMonthPlanId = row.drivingMonthPlanId || this.ids
      getDrivingMonthPlan(drivingMonthPlanId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改掘进月计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.drivingMonthPlanId != null) {
            updateDrivingMonthPlan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDrivingMonthPlan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const drivingMonthPlanIds = row.drivingMonthPlanId || this.ids;
      this.$modal.confirm('是否确认删除掘进月计划编号为"' + drivingMonthPlanIds + '"的数据项？').then(function() {
        return delDrivingMonthPlan(drivingMonthPlanIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dispatch/drivingMonthPlan/export', {
        ...this.queryParams
      }, `drivingMonthPlan_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
